package com.alphacsp.theedge2012.data.adapters;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.alphacsp.theedge2012.R;
import com.alphacsp.theedge2012.data.entities.Speaker;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Gilad
 * Date: 20/10/10
 * Time: 15:15
 */
public class SpeakersAdapter extends ArrayAdapter<Speaker> {

    private int resourceId = 0;
    private LayoutInflater inflater;

    public SpeakersAdapter(Context context, int textViewResourceId, List<Speaker> objects) {
        super(context, 0, objects);
        this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.speakers_list, parent, false);
        }
        final TextView speakerName = (TextView) convertView.findViewById(R.id.speaker_name);
        final TextView speakerCompany = (TextView) convertView.findViewById(R.id.speaker_company);
        final ImageView speakerImage = (ImageView) convertView.findViewById(R.id.speaker_image);
        speakerImage.setTag(position);

        Speaker speaker = getItem(position);
        speakerName.setText(speaker.getName());
        speakerCompany.setText(speaker.getCompany());
        final Bitmap image = speaker.getSpeakerImage();
        if (image != null) {
            speakerImage.setImageBitmap(image);
        }

        return convertView;
    }
}
